import React,{Component} from 'react'
export default class Form extends Component{
    constructor(){
        super()
        this.state={
            user:'',
            age:''
        }
    }
    changeInput = (event) => {
        this.setState({
            [event.target.name]: event.target.value
        })
    }
    add = () => {
        let obj = { "id": +new Date(), "user": this.state.user, "age": this.state.age };
        this.props.addList(obj)
    }
    render(){
        return (
            <form action="">
                <div>
                    <input type="text" value={this.state.user} name="user" onChange={this.changeInput} />
                </div>
                <div>
                    <input type="text" value={this.state.age} name="age" onChange={this.changeInput} />
                </div>
                <div>
                    <input type="button" value="添加" onClick={this.add} />
                </div>
            </form>
        )
    }
}